﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ZQNB.Common.Ioc;

namespace ZQNB.Web.Common.Contexts
{
    public class NbUser
    {
        public NbUser()
        {
            //this.RoleCodes = new List<string>();
        }

        //public IList<string> Codes { get; set; }

        public Guid OrgId { get; set; }
        public Guid UserId { get; set; }
        public string HeadLogo { get; set; }
        public string LoginName { get; set; }
        public string RealName { get; set; }
        public string Email { get; set; }
        public string CustomNo { get; set; }
        public string NickName { get; set; }
        public string UserTypeCode { get; set; }
    }

    public interface INbUserContext
    {
        NbUser GetCurrentNbUser();
    }

    public class NbUserContext : INbUserContext
    {
        public static INbUserContext Current
        {
            get
            {
                return CoreServiceProvider.LocateService<INbUserContext>();
            }
        }
        public NbUser GetCurrentNbUser()
        {
            var loginName = Thread.CurrentPrincipal.Identity.Name;
            if (string.IsNullOrEmpty(loginName))
            {
                return null;
            }
            return new NbUser() { LoginName = loginName};
        }
    }
}
